﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using SimpleServiceBus.Bus;
using SimpleServiceBus.StructureMap;
using SimpleServiceBus.Tests.Stubs;
using SimpleServiceBus.Utilities.ObjectBuilder;
using StructureMap;

namespace SimpleServiceBus.Tests.Utilities.ObjectBuilder.StructureMap
{
    [TestFixture]
    public class StructureMapObjectBuilderTestFixture
    {
        [Test]
        public void ShouldProvideConfiguredTypeWhenRequested()
        {

            //Given
            var builder = new StructureMapObjectBuilder();
            var builderService = new DefaultObjectBuilderService(builder);

            StructureMapConfiguration.ForRequestedType<IObjectBuilder>().TheDefaultIsConcreteType
               <DefaultObjectBuilder>();
            
            //When
            var built = builderService.BuildObject<IObjectBuilder>();
            
            //Then
            Assert.IsNotNull(built);
            Assert.That(built, Is.InstanceOfType(typeof (DefaultObjectBuilder)));
        }

        [Test]
        public void ShouldProvideDefaultInstanceWhenRequestedTypeIsNotRegistered()
        {
            //Given
            var builder = new StructureMapObjectBuilder();
            var builderService = new DefaultObjectBuilderService(builder);

            //When
            var built = builderService.BuildService<IMessageBus, TestBus>();
            Assert.IsNotNull(built);
            Assert.That(built, Is.InstanceOfType(typeof (TestBus)));
        }
    }
}
